package com.TTBook.common.queue;

import java.util.LinkedList;

public abstract class AbstractQueue {
	private static final int MAX_LIST_SIZE = 100000;
	private LinkedList queue;
	private int max_size;
	
	public AbstractQueue()
	{
		queue = new LinkedList();
		this.max_size = MAX_LIST_SIZE;
	}
	public AbstractQueue(int size)
	{
		queue = new LinkedList();
		this.max_size = size;
	}
	public synchronized int put(Object msg)
	{
		int tmp = queue.size();
		if(tmp >= max_size)
		{
			return 999;
		}
		queue.addLast(msg);
		if(tmp <= 0)
		{
			notify();
		}
		return 0;
	}
	public synchronized Object take()
	{
		if(queue.size()>0)
		{
			return queue.removeFirst();
		}
		else
		{
			try {
				wait();
			} catch (InterruptedException e) {
				e.getMessage();
			}
		}
		return null;
	}
	abstract public int handle(Object msg);
}
